package com.webdemo08.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.webdemo08.actionform.UserForm;
import com.webdemo08.pojo.User;
import com.webdemo08.service.UserService;

public class UpdateUser extends DispatchAction {

	private UserService userService;

	public UserService getUserService() {
		return userService;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	public ActionForward showUi(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse resposne) throws Exception {
		UserForm userForm =(UserForm)form;
		User user = userService.getUser(userForm.getId());
		request.setAttribute("user", user);
		return mapping.findForward("updateui");
	}
	public ActionForward update(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse resposne) throws Exception {
		UserForm userForm =(UserForm)form;
		User user = new User();
		user.setId(userForm.getId());
		user.setName(userForm.getName());
		userService.updateUser(user);
		ActionForward actionForward = new ActionForward("/queryUser.do");
		return actionForward;
	}


}
